<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class NewsTypeRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $editRules = [
            'name'   => 'required',
            'code'   => 'required',
            'status' => 'required|boolean',
            'hot'    => 'required|boolean',
        ];

        $createRules = [
            'name'   => 'required|unique:article_category,name',
            'code'   => 'required|unique:article_category,code',
            'status' => 'required|boolean',
            'hot'    => 'required|boolean',
            'upid'   => 'required|numeric',
        ];

//        return array();

        $data = Request::all();
        if ($data['formType'] == 'create') {
            return $createRules;
        }

        return $editRules;
    }

    public function attributes()
    {
        $attributes = array(
            'name'   => '名称',
            'code'   => 'code',
            'status' => '是否可用',
            'hot'    => '是否热门',
            'upid'   => '父分类',
        );

        return $attributes;
    }

    public function messages()
    {
        $messages = [
            'required'       => ':attribute为必填选项',
            'numeric'        => ':attribute必须为数字',
            'status.boolean' => ':attribute必须为可用、不可用的一种',
            'hot.boolean'    => ':attribute必须为热门、普通的一种',
            'code.unique'    => ':attribute必须不能重复',
            'name.unique'    => ':attribute必须不能重复',
        ];

        return $messages;
    }
}
